package com.itheima.Demo05;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

//通过继承方式解决卖票问题;
public class AAA extends Thread {
    //因为通过继承解决,所以必须定义成静态变量才可以被其他线程所调用;
    static int a = 100;
    //创建静态锁;
    static Lock l = new ReentrantLock();
    //重写run方法;

    @Override
    public void run() {
        while (true) {
            //加锁;
            l.lock();
            if (a <= 0) {
                l.unlock();
                break;
            }
            System.out.println(Thread.currentThread().getName() + "售出了" + a + "号票");
            a--;
            //解锁;
            l.unlock();
        }
    }
}
